﻿using Client.Constant;
using Client.Framework.Message;
using Client.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Client.Message.Response
{
    [MessageAttr(MessageId.PERMISSION_LIST)]
    class PermissionListResp : ResponseBaseMessage
    {
        public List<ViewPermisson> Permissions { get; } = new List<ViewPermisson>();
        public int Count { get; set; }

        public override void Deserialize(byte[] buffer)
        {
            PermissionList msg = PermissionList.Parser.ParseFrom(buffer);
            foreach (var permission in msg.Permissions)
            {
                ViewPermisson viewPermission = new ViewPermisson
                {
                    ID = permission.Id,
                    PerCode = permission.PerCode,
                    Status = (Enum.DataStatus)permission.Status,
                    Sort = permission.Sort,
                    Creator = permission.Creator,
                    CreateTime = permission.CreateTime,
                    Updator = permission.Updator,
                    UpdateTime = permission.UpdateTime
                };
                Permissions.Add(viewPermission);
            }
            Count = msg.Count;
        }
    }
}
